package com.briup.operator.service.impl;

import com.briup.operator.entity.Category;
import com.briup.operator.entity.extend.OperatorEx;
import com.briup.operator.mapper.CategoryMapper;
import com.briup.operator.mapper.extend.CategoryExtendMapper;
import com.briup.operator.service.ICategoryService;
import com.briup.operator.service.IOpeatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 算子分类实现类
 */
@Service
public class CategoryServiceImpl implements ICategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private CategoryExtendMapper categoryExtendMapper;
    @Autowired
    private IOpeatorService operatorService;

    // 查询所有算子分类信息
    @Override
    public List<Category> findAll() {
        return categoryExtendMapper.findAll();
    }

    // 根据算子分类id查询算子分类详情
    @Override
    public Category findById(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    // 根据用户id查询算子目录信息
    @Override
    public List<Category> findCategoryByUserId(int userId) {
        // 1.根据用户id查询算子以及目录信息
        List<OperatorEx> operatorExList = operatorService.findOperatorByUserId(userId);
        List<Category> categoryList = new ArrayList<>();
        // 2.将算子的目录信息抽取返回
        operatorExList.forEach(operatorEx->{
            categoryList.add(operatorEx.getCategory());
        });
        return categoryList;
    }
}
